﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text;
using QuanLyBanHang.DAL;
using QuanLyBanHang_NewApp.Entity;
using QuanLyBanHang_NewApp.DAL;

namespace QuanLyBanHang_NewApp.BUS
{
    public class PhieuNhapBUS
    {
        PhieuNhapDAL pnDal;

        public PhieuNhapBUS()
        {
            pnDal = new PhieuNhapDAL();
        }

        public bool luuPhieuNhap(PhieuNhap pn, long manv)
        {
            long mapn;
            long mancc = long.Parse(pn.getAttribute("mancc"));
            double tonggia = double.Parse(pn.getAttribute("tonggia"));

            if (pnDal.insertPN(out mapn, manv, mancc, tonggia))
            {
                foreach (SanPham sp in pn.getDetail())
                {
                    if (!pnDal.insertCTPN(mapn, long.Parse(sp.getAttribute(0)),
                        long.Parse(sp.getAttribute(4)), double.Parse(sp.getAttribute(3)))) return false;
                    
                }
                return true;
            }
            return false;


        }
    }
}
